﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WJ.Infrastructure.CQRS;
using WJ.Infrastructure.RabbitMQ;
using WJ.Infrastructure.Serializer;

namespace RabbitMQTest
{
    class Program
    {
        static void Main(string[] args)
        {
            IMessageBus messageBus = new MessageBus();


            messageBus.Subscribe((message) =>
            {
                Console.WriteLine("订阅a：" + message.ToJson());
            }, new[] { "a" }, "a");

            messageBus.Subscribe((message) =>
            {
                Console.WriteLine("订阅b：" + message.ToJson());
            }, new[] {  "b" }, "b");


            messageBus.Subscribe((message) =>
            {
                Console.WriteLine("订阅c：" + message.ToJson());
            }, new[] { "c" }, "c");

            messageBus.Subscribe((message) =>
            {
                Console.WriteLine("订阅d：" + message.ToJson());
            }, new[] { "d" }, "d");



            for (int i = 0; i < 1; i++)
            {
                var message = new Message() { Id = i.ToString(), ToPic = "a", Body = "a" + i };
                messageBus.Publish(message);
                Console.WriteLine("发送消息：" + message.ToJson());
            }

            for (int i = 0; i < 1; i++)
            {
                var message = new Message() { Id = i.ToString(), ToPic = "b", Body = "b" + i };
                messageBus.Publish(message);
                Console.WriteLine("发送消息：" + message.ToJson());
            }
            for (int i = 0; i < 1; i++)
            {
                var message = new Message() { Id = i.ToString(), ToPic = "c", Body = "c" + i };
                messageBus.Publish(message);
                Console.WriteLine("发送消息：" + message.ToJson());
            }
            for (int i = 0; i < 1; i++)
            {
                var message = new Message() { Id = i.ToString(), ToPic = "d", Body = "d" + i };
                messageBus.Publish(message);
                Console.WriteLine("发送消息：" + message.ToJson());
            }

            for (int i = 0; i < 1; i++)
            {
                var message = new Message() { Id = i.ToString(), ToPic = "*", Body = "发送给所有" + i };
                messageBus.Publish(message);
                Console.WriteLine("发送消息：" + message.ToJson());
            }



            Console.ReadLine();
        }
    }

    [Serializable]
    public class Message : IMessage
    {
        public string Id { get; set; }
        public string ToPic { get; set; }
        public string Body { get; set; }
    }
}
